# -*- coding:utf-8 -*-
"""
Create by Jim on2018/12/28
"""
import logging
from datetime import timedelta
from logging.handlers import RotatingFileHandler
import pymysql
from redis import StrictRedis

__author__ = "Jim"


class Config():
    DEBUG = True

    SELECT_KEY = '\xbcS\x89K\xc5\xa3\x13\xc1W\x80\x1a\x9d\xa7\x07\xb7\xa0T|z\xfc\x1f\x9d\xfe/\x0e\x96F\x17\x7f\x16\x9b\xe9'
    SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:@localhost:3306/test'
    SQLALCHEMY_TRACK_MODIFICATIONS = True

    REDIS_HOST = '127.0.0.1'
    REDIS_PASSWORD = 'jim'
    REDIS_PORT = 6379

    SESSION_TYPE = 'redis'
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWORD)
    SESSION_USE_SIGNER = True
    PERMANENT_SESSION_LIGETIME = timedelta(days=2)

    # 日志文件配置
    # 设置日志的记录等级,等级有大小关系:DEBUG<INFO<WARING<ERROR,
    logging.basicConfig(level=logging.DEBUG)  # 调试debug级,大于等于DEBUG模式的内容输出才会打印
    # 创建日志记录器，指明日志保存的路径、每个日志文件的最大大小、保存的日志文件个数上限
    file_log_handler = RotatingFileHandler("app/logs/log", maxBytes=1024 * 1024 * 100, backupCount=10)
    # 创建日志记录的格式 日志等级 输入日志信息的文件名 行数 日志信息
    formatter = logging.Formatter('%(levelname)s %(filename)s:%(lineno)d %(message)s')
    # 为刚创建的日志记录器设置日志记录格式
    file_log_handler.setFormatter(formatter)
    # 为全局的日志工具对象（flask app使用的）添加日志记录器
    logging.getLogger().addHandler(file_log_handler)


class Develop(Config):
    pass


class Product(Config):
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = 'mysql+cymysql://root:@localhost:3306/test'

    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 3306
    PERMANENT_SESSION_LIGETIME = timedelta(days=2)

    logging.basicConfig(level=logging.INFO)  # 调试debug级,大于等于DEBUG模式的内容输出才会打印


class Test(Config):
    pass


env = {
    'dev': Develop,
    'prd': Product,
    'test': Test,
}
